/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.pku.sei.ocl.cst.impl;

import edu.pku.sei.ocl.cst.CSTPackage;
import edu.pku.sei.ocl.cst.DefCS;
import edu.pku.sei.ocl.cst.DefExpressionCS;
import edu.pku.sei.ocl.evaluation.Context;
import edu.pku.sei.ocl.visitor.AbstractOCLVisitor;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Def CS</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.DefCSImpl#getDefExpressionCS <em>Def Expression CS</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.DefCSImpl#isStatic <em>Static</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DefCSImpl extends InvOrDefCSImpl implements DefCS {
	/**
	 * The cached value of the '{@link #getDefExpressionCS() <em>Def Expression CS</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDefExpressionCS()
	 * @generated
	 * @ordered
	 */
	protected DefExpressionCS defExpressionCS;

	/**
	 * The default value of the '{@link #isStatic() <em>Static</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isStatic()
	 * @generated
	 * @ordered
	 */
	protected static final boolean STATIC_EDEFAULT = false;

	/**
	 * The flag representing the value of the '{@link #isStatic() <em>Static</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isStatic()
	 * @generated
	 * @ordered
	 */
	protected static final int STATIC_EFLAG = 1 << 8;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DefCSImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CSTPackage.Literals.DEF_CS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DefExpressionCS getDefExpressionCS() {
		return defExpressionCS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDefExpressionCS(
			DefExpressionCS newDefExpressionCS, NotificationChain msgs) {
		DefExpressionCS oldDefExpressionCS = defExpressionCS;
		defExpressionCS = newDefExpressionCS;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET, CSTPackage.DEF_CS__DEF_EXPRESSION_CS,
					oldDefExpressionCS, newDefExpressionCS);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDefExpressionCS(DefExpressionCS newDefExpressionCS) {
		if (newDefExpressionCS != defExpressionCS) {
			NotificationChain msgs = null;
			if (defExpressionCS != null)
				msgs = ((InternalEObject) defExpressionCS).eInverseRemove(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.DEF_CS__DEF_EXPRESSION_CS, null,
						msgs);
			if (newDefExpressionCS != null)
				msgs = ((InternalEObject) newDefExpressionCS).eInverseAdd(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.DEF_CS__DEF_EXPRESSION_CS, null,
						msgs);
			msgs = basicSetDefExpressionCS(newDefExpressionCS, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.DEF_CS__DEF_EXPRESSION_CS, newDefExpressionCS,
					newDefExpressionCS));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isStatic() {
		return (eFlags & STATIC_EFLAG) != 0;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStatic(boolean newStatic) {
		boolean oldStatic = (eFlags & STATIC_EFLAG) != 0;
		if (newStatic)
			eFlags |= STATIC_EFLAG;
		else
			eFlags &= ~STATIC_EFLAG;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.DEF_CS__STATIC, oldStatic, newStatic));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case CSTPackage.DEF_CS__DEF_EXPRESSION_CS:
			return basicSetDefExpressionCS(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case CSTPackage.DEF_CS__DEF_EXPRESSION_CS:
			return getDefExpressionCS();
		case CSTPackage.DEF_CS__STATIC:
			return isStatic();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case CSTPackage.DEF_CS__DEF_EXPRESSION_CS:
			setDefExpressionCS((DefExpressionCS) newValue);
			return;
		case CSTPackage.DEF_CS__STATIC:
			setStatic((Boolean) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case CSTPackage.DEF_CS__DEF_EXPRESSION_CS:
			setDefExpressionCS((DefExpressionCS) null);
			return;
		case CSTPackage.DEF_CS__STATIC:
			setStatic(STATIC_EDEFAULT);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case CSTPackage.DEF_CS__DEF_EXPRESSION_CS:
			return defExpressionCS != null;
		case CSTPackage.DEF_CS__STATIC:
			return ((eFlags & STATIC_EFLAG) != 0) != STATIC_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (static: "); //$NON-NLS-1$
		result.append((eFlags & STATIC_EFLAG) != 0);
		result.append(')');
		return result.toString();
	}

	@Override
	public Object accept(AbstractOCLVisitor v, Context env, Object... argv) {
		if (argv == null || argv.length == 0) {
			return v.visitDefCS(this, env);
		} else {
			return v.visitDefCS(this, env, argv);
		}
	}

} //DefCSImpl
